package com.gaogzhen.controller;

import com.gaogzhen.domain.Account;
import com.gaogzhen.feign.AccountServiceFeign;
import com.gaogzhen.service.AccountService;
import com.gaogzhen.utils.CurrentUser;
import com.gaogzhen.utils.R;
import com.gaogzhen.vo.SymbolAssetVo;
import com.gaogzhen.vo.UserTotalAccountVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;

/**
 * @author Administrator
 * @version 1.0
 * @description
 * @date 2022-11-27 11:35
 */
@Api(tags = "账户控制器")
@RestController
@RequestMapping("/account")
public class AccountController implements AccountServiceFeign {

    @Autowired
    private AccountService accountService;

    @GetMapping("/{coinCode}")
    @ApiOperation(value = "查找当前用户相货币资产")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "coinCode",value = "币种")
    })
    public R<Account> getUserAccount(@PathVariable(name = "coinCode")String coinCode) {
        return R.ok(accountService.getUserAccount(CurrentUser.getCurrentUserId(), coinCode));
    }

    @GetMapping("/total")
    @ApiOperation(value = "计算用户的总资产")
    public R<UserTotalAccountVo> total() {
        return R.ok(accountService.total(CurrentUser.getCurrentUserId()));
    }

    @GetMapping("/asset/{symbol}")
    @ApiOperation(value = "获取交易对资产")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "symbol",value = "交易对")
    })
    public R<SymbolAssetVo> getSymbolAsset(@PathVariable("symbol")String symbol) {
        return R.ok(accountService.getSymbolAsset(CurrentUser.getCurrentUserId(), symbol));
    }

    /**
     * 锁定用户的余额
     *
     * @param userId  用户的id
     * @param coinId  币种的id
     * @param mum     锁定的数量
     * @param type    业务类型
     * @param orderId 订单编号
     * @param fee
     */
    @Override
    public void lockUserAmount(Long userId, Long coinId, BigDecimal mum, String type, Long orderId, BigDecimal fee) {
        accountService.lockUserAmount(userId, coinId, mum, type, orderId, fee);
    }

    /**
     * 划转买入的账户余额
     *
     * @param fromUserId
     * @param toUserId
     * @param coinId
     * @param amount
     * @param businessType
     * @param orderId
     */
    @Override
    public void transferBuyAmount(Long fromUserId, Long toUserId, Long coinId, BigDecimal amount, String businessType, Long orderId) {
        accountService.transferBuyAmount(fromUserId, toUserId, coinId, amount, businessType, orderId);
    }

    /**
     * 划转出售的成功的账户余额
     *
     * @param fromUserId
     * @param toUserId
     * @param coinId
     * @param amount
     * @param businessType
     * @param orderId
     */
    @Override
    public void transferSellAmount(Long fromUserId, Long toUserId, Long coinId, BigDecimal amount, String businessType, Long orderId) {
        accountService.transferSellAmount(fromUserId, toUserId, coinId, amount, businessType, orderId);
    }
}
